#!/bin/bash
##Docker安装脚本
install_docker-ce_install-docker(){
	Entering "Docker安装..."
	srv='docker-ce'
	if [[ "$Package_managements" == 'apt' ]];then
		srv='docker.io'
		echo '暂时使用io'
	elif [[ "$Package_managements" == 'yum' ]];then
		srv='docker-ce'
		service_chek "$srv"
		if [[ "$System_version" == '7' ]];then
			re=`yum list docker-ce --showduplicates|sort -r | awk '{print $2}' | awk 'NR>6{print}'|sed 's/base://'| awk NF |sed 's/3://'`
			for i in $re;do
				green_zt $i
			done
			green_zt "请选择一个docker版本并粘贴\n默认安装最新版"
			input "低版本很有可能安装失败,建议安装较新版本" "docker_ver"
			if [[ -z "$docker_ver" ]];then
				green_zt "已选择安装最新版本"
				dockers="$srv"
			else
				if [[ -z `echo $re | grep "$docker_ver"` ]];then
					red_bg "好像你输入的版本并不在上面的列表中"
					green_zt "已默认安装最新版"
				else
					green_zt "已选择安装${docker_ver}"
					srv="${srv}-${docker_ver}"
				fi
			fi
		fi
		Entering "Docker安装..."
		
	fi
	service_install "$srv" 
	chek_status "$?" "${srv}安装"
}
install_docker-ce_docker-config(){
	mkdir -p  /etc/docker/
	echo -e "{\n\t\"exec-opts\": [\"native.cgroupdriver=systemd\"],\n\t\"registry-mirrors\": [\"https://ung2thfc.mirror.aliyuncs.com\"]\n}" > /etc/docker/daemon.json
	service_start "docker"
	chek_status "$?" "Docker镜像加速地址配置"
	install_docker-ce_get_docker_version
	green_zt "[ Docker ]安装成功"
}
install_docker-ce_get_docker_version(){
    Dcoker_C_ver=`docker version | grep Version | awk '{print $2}' |sed -n 1p`
    Dcoker_S_ver=`docker version | grep Version | awk '{print $2}' |sed -n 2p`
	Docker_Cgroup=`docker info | grep 'Cgroup Driver' | sed 's/Cgroup Driver://'`
	red_z_green_z "Docker客户端版本:" "[ $Dcoker_C_ver ]"
	red_z_green_z "Docker服务端版本:" "[ $Dcoker_S_ver ]"
	red_z_green_z "当前Docker存储驱动:" "[ $Docker_Cgroup ]"
	red_z_green_z "当前镜像加速地址:" "[ 阿里云 ]"
	input "是否进入Docker工具箱 [ y/n ],默认[ n ]" docker_tools
	if [[ "$docker_tools" == 'y' ]];then
		Loading_function './tools/Docker_tools.sh'
		tools_menu-docker
	fi
}
